package com.chen.mapper;

import com.chen.popj.dto.UserDTO;
import com.chen.popj.entity.User;
import com.chen.popj.vo.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查找用户
     *
     * @param username
     * @return
     */
    @Select("select * from user where username= #{username}")
    User queryByUsername(String username);

    /**
     * 用户注册
     *
     * @param user
     */
    @Insert("insert into user (username, password, create_time) " +
            "values(#{username},#{password},now())")
    void register(User user);

    /**
     * 根据用户id查询用户名
     *
     * @param userId
     * @return
     */
    @Select("select username from user where id = #{userId}")
    String queryUsernameById(Integer userId);

    /**
     * 根据用户id查询用户基本资料
     *
     * @param userId
     * @return
     */
    @Select("select user.username,user.email from user where id=#{userId}")
    UserVO getUserInfo(Integer userId);

    /**
     * 根据用户id修改用户信息
     */
    void Update(User user);

    /**
     * 根据用户id查询用户密码
     *
     * @param userId
     * @return
     */
    @Select("select password from user where id=#{userId}")
    String queryPasswordById(Integer userId);

    /**
     * 根据用户id获取用户头像
     * @param userId
     * @return
     */
    @Select("select avatar from user where id=#{userId}")
    String getUserAvatar(Integer userId);
}
